/**
 * 
 */
package com.lazyshopkeeper.front.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.lazyshopkeeper.front.common.Constant;
import com.lazyshopkeeper.front.common.Util;

/**
 * @author xuyuqi
 *
 */
public class TopInterceptor extends HandlerInterceptorAdapter {

	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		if(request.getSession().getAttribute("sessionKey") == null){
			String topSession = request.getParameter("top_session");
			// TODO 转登陆页面
			if(topSession == null) {
				response.sendRedirect(Constant.LOGIN_URL);
				return false;
			}
			String topParameters = request.getParameter("top_parameters");
			String nick = Util.ParametersName(topParameters);
			
			request.getSession().setAttribute(Constant.SESSION_KEY, topSession);
			request.getSession().setAttribute(Constant.NICK, nick);
			request.getSession().setMaxInactiveInterval(3000);
		}
		
		return true;
	}

}
